package masterjava.admingui.shared.entity;

import masterjava.admingui.shared.RoleType;
import masterjava.common.shared.entity.BaseEntity;

import javax.persistence.*;
import java.util.Date;

/**
 * User: Grigory Kislin
 * Date: 23/06/11
 */

@MappedSuperclass
public class Client extends BaseEntity {

    public Client() {
    }

    public Client(RoleType role, String email) {
        this.role = role;
        this.email = email;
    }

    public Client(RoleType role, String email, String address, Date startDate, Date endDate, String comments, Attachment logo) {
        this.role = role;
        this.email = email;
        this.address = address;
        this.comments = comments;
        this.startDate = startDate;
        this.endDate = endDate;
        this.logo = logo;
    }

    protected String address;

    protected RoleType role;

    protected String email;

    protected Date startDate;

    protected Date endDate;

    protected String comments;

    // do not serialized
    transient protected Attachment logo;

    private Long logoId=null;


    @Column(name = "EMAIL", nullable = false)
    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    @Column(name = "ROLE", nullable = false)
    @Enumerated(EnumType.STRING)
    public RoleType getRole() {
        return role;
    }

    public void setRole(RoleType role) {
        this.role = role;
    }

    @Column(name = "COMMENTS")
    public String getComments() {
        return comments;
    }

    public void setComments(String comments) {
        this.comments = comments;
    }

    @Column(name = "ADDRESS")
    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    @Temporal(TemporalType.DATE)
    @Column(name = "START_DATE")
    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "LOGO")
    public Attachment getLogo() {
        return logo;
    }

    public void setLogo(Attachment logo) {
        this.logo = logo;
    }

    @Transient
    public Long getLogoId() {
        return logoId;
    }

    @Override
    public void prepareToSerialize() {
        logoId = evalEntityId(logo);
    }
}
